/*
 * PayeeTests.java
 *
 *  
 */
package org.msb.finance.data;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

/**
 * 
 * 
 * @author Marc Boudreau
 * 
 */
@SuppressWarnings("nls")
public class PayeeTests {

	/*
	 * 
	 */
	private Payee payee;

	/**
	 * @throws Exception
	 */
	@Before
	public void setUp() throws Exception {
		payee = new Payee("Test Payee");
	}

	/**
	 * Test method for {@link Payee#hashCode()}.
	 * 
	 * @throws Exception
	 */
	@Test
	public void testHashCode() throws Exception {
		Payee p1 = new Payee(payee.getName());

		assertTrue(payee.hashCode() == p1.hashCode());

		Payee p2 = new Payee(payee.getName() + "-ZZZ");

		assertFalse(payee.hashCode() == p2.hashCode());

		Payee p3 = new Payee("AAAA");
		String s3 = new String("AAAA");

		assertFalse(p3.hashCode() == s3.hashCode());
	}

	/**
	 * Test method for {@link Payee#Payee()}.
	 * 
	 * @throws Exception
	 */
	@Test
	public void testPayee() throws Exception {
		assertNotNull(payee);
	}

	/**
	 * Test method for {@link Payee#setName(String)}.
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetName() throws Exception {
		final String NAME = "New Test Payee";
		payee.setName(NAME);

		assertEquals(NAME, payee.getName());

		final String NAME2 = "New Test Payee 2";
		payee.setName(NAME2);

		assertEquals(NAME2, payee.getName());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetNameToNonExistingName() throws Exception {
		Payee p1 = new Payee("Test Payee 2");
		Cabinet cabinet = new Cabinet(null);

		cabinet.addPayee(payee);
		cabinet.addPayee(p1);

		final String NAME = "Test Payee-ZZZZ";
		p1.setName(NAME);
		assertEquals(NAME, p1.getName());
	}

	/**
	 * Test method for {@link Payee#setAccountNum(String)}.
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetAccountNum() throws Exception {
		final String ACCOUNTNUM = "00-12345678";
		payee.setAccountNum(ACCOUNTNUM);

		assertEquals(ACCOUNTNUM, payee.getAccountNum());

		final String ACCOUNTNUM2 = "00-12345679";
		payee.setAccountNum(ACCOUNTNUM2);

		assertEquals(ACCOUNTNUM2, payee.getAccountNum());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetAccountNumToNull() throws Exception {
		payee.setAccountNum(null);

		assertNull(payee.getAccountNum());
	}

	/**
	 * Test method for {@link Payee#setAddress(String)}.
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetAddress() throws Exception {
		final String ADDRESS = "125 Maple Drive, Springfield CO";
		payee.setAddress(ADDRESS);

		assertEquals(ADDRESS, payee.getAddress());

		final String ADDRESS2 = "850 5th Ave, New York NY";
		payee.setAddress(ADDRESS2);

		assertEquals(ADDRESS2, payee.getAddress());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetAddressToNull() throws Exception {
		payee.setAddress(null);

		assertNull(payee.getAddress());
	}

	/**
	 * Test method for {@link Payee#setPhone(String)}.
	 */
	@Test
	public void testSetPhone() {
		final String PHONE = "212-555-5555";
		payee.setPhone(PHONE);

		assertEquals(PHONE, payee.getPhone());

		final String PHONE2 = "626-555-5555";
		payee.setPhone(PHONE2);

		assertEquals(PHONE2, payee.getPhone());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetPhoneToNull() throws Exception {
		payee.setPhone(null);

		assertNull(payee.getPhone());
	}

	/**
	 * Test method for {@link Payee#setWebsite(String)}.
	 */
	@Test
	public void testSetWebsite() {
		final String WEBSITE = "http://www.payee.com";
		payee.setWebsite(WEBSITE);

		assertEquals(WEBSITE, payee.getWebsite());

		final String WEBSITE2 = "https://www.payee-2.com";
		payee.setWebsite(WEBSITE2);

		assertEquals(WEBSITE2, payee.getWebsite());
	}

	/**
	 * Test method for {@link Payee#setEmail(String)}.
	 */
	@Test
	public void testSetEmail() {
		final String EMAIL = "joe.smith@payee.com";
		payee.setEmail(EMAIL);

		assertEquals(EMAIL, payee.getEmail());

		final String EMAIL2 = "fred.jones@payee.com";
		payee.setEmail(EMAIL2);

		assertEquals(EMAIL2, payee.getEmail());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetEmailToNull() throws Exception {
		payee.setEmail(null);

		assertNull(payee.getEmail());
	}

	/**
	 * Test method for {@link Payee#compareTo(Payee)}.
	 */
	@Test
	public void testCompareTo() {
		Payee p1 = new Payee("AAA-" + payee.getName());
		Payee p2 = new Payee("ZZZ-" + payee.getName());

		assertEquals(0, payee.compareTo(payee));

		assertTrue(0 < payee.compareTo(p1));
		assertTrue(0 > payee.compareTo(p2));

		assertTrue(0 > p1.compareTo(p2));
		assertTrue(0 < p2.compareTo(p1));

		try {
			payee.compareTo(null);
			fail("Expected a NullPointerException to be thrown.");
		} catch (NullPointerException ex) {
			// Pass.
		}
	}

	/**
	 * Test method for {@link Payee#equals(Object)}.
	 */
	@Test
	public void testEqualsObject() {
		Payee p1 = payee;
		Payee p2 = new Payee(payee.getName());
		Payee p3 = new Payee(payee.getName() + "-ZZZZ");

		assertTrue(payee.equals(payee));
		assertFalse(payee.equals(null));

		assertTrue(payee.equals(p1));
		assertTrue(p1.equals(payee));

		assertTrue(payee.equals(p2));
		assertTrue(p2.equals(payee));

		assertTrue(p1.equals(p2));
		assertTrue(p2.equals(p1));

		assertFalse(payee.equals(p3));
		assertFalse(p3.equals(payee));

		assertFalse(payee.equals(new Object()));
	}
}
